#ifndef _IR_H_
#define _IR_H_

#include "symbol.h"

typedef struct st_semt_stmt *semt_stmt;

typedef struct st_semt_exp *semt_exp;

typedef struct st_semt_explist *semt_explist;

typedef enum { SM_PLUS, SM_MINUS, SM_TIMES, SM_DIVIDE,      // calc op
               SM_ADDR, SM_DEREF,
               SM_EQ, SM_NEQ, SM_GT, SM_LT, SM_GE, SM_LE,   // rel  op
               SM_AND, SM_OR,                                // logic op
} semt_op ;

struct st_semt_stmt {
    enum { S_SEQ, S_LAB, S_JMP, S_CJMP, S_MV, S_EXP } kind;
    union {
        struct { semt_stmt left, right; } seq;
        symbol lab;
        struct {
            semt_exp pos;
            //symbollist labs;
        } jmp;
        struct {
            semt_exp cond;
            symbol true_lab, false_lab;
        } cjmp;
        struct { semt_exp dst, src; } mv;
        semt_exp exp;
    } u;
};

struct st_semt_exp {
    enum { E_MEM, E_TMP, E_ESEQ, E_NAME, E_CONST, E_CALL, E_OP } kind;
    union {
        struct {
            semt_exp pos;
            unsigned int cnt /* WORDS */;
        } mem;
        symbol tmp;
        struct {
            semt_stmt stmt;
            semt_exp exp;
        } eseq;
        symbol lab;
        int constt;
        struct {
            semt_exp func;
            semt_explist args;
        } call;
        struct {
            semt_op op;
            semt_exp left, right;
        } bop;
    } u;
};



#endif